package com.first.first.pojo;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

public class ResponseMessage<T> {
    private Integer code;
    private String msg;
    private T data;

    public ResponseMessage(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    @Contract(value = "_ -> new", pure = true)
    public static <T> @NotNull ResponseMessage<T> success(T data) {
        return new ResponseMessage<>(1, "success", data);
    }

    @org.jetbrains.annotations.NotNull
    @org.jetbrains.annotations.Contract(value = "_, _ -> new", pure = true)
    public static <T> ResponseMessage<T> error(String msg, T data) {
        return new ResponseMessage<>(0, msg, data);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
